import request from '@/axios';
import {baseUrl} from '@/config/env';


export const list = (data) => {
    return request({
            url: baseUrl + '/start/formEngine/form/page',
            method: 'get',
            params: data
        }
    )
}
export const pageHistory = (data) => {
    return request({
            url: baseUrl + '/start/formEngine/form/pageHistory',
            method: 'get',
            params: data
        }
    )
}
export const add = (data, synchronization = false) => {
    return request({
            url: baseUrl + '/start/formEngine/form/add?synchronization=' + synchronization,
            method: 'post',
            data: data
        }
    )
}

export const getById = (id) => {
    return request({
            url: baseUrl + '/start/formEngine/form/getById/' + id,
            method: 'get',
        }
    )
}

export const updateById = (data, synchronization = false) => {
    return request({
            url: baseUrl + '/start/formEngine/form/updateById?synchronization=' + synchronization,
            method: 'put',
            data: data
        }
    )
}

export const deleteById = (id) => {
    return request({
            url: baseUrl + '/start/formEngine/form/deleteById/' + id,
            method: 'delete',
        }
    )
}

export const getByTableId = (tableId) => {
    return request({
            url: baseUrl + '/start/formEngine/form/getByTableId/' + tableId,
            method: 'get',
        }
    )
}
export const createMenu = (tableId, data) => {
    return request({
            url: baseUrl + '/start/formEngine/form/createMenu/' + tableId,
            method: 'get',
            params: data,
        }
    )
}
export const getTableOption = (tableId) => {
    return request({
            url: baseUrl + '/start/formEngine/form/getTableOption/' + tableId,
            method: 'get',
        }
    )
}


export const saveTableOption = (tableId, data) => {
    return request({
            url: baseUrl + '/sysFormConfig/saveTableOption/' + tableId,
            method: 'post',
            data: data,
        }
    )
}

export const synchronizationTable = (tableId) => {
    return request({
            url: `${baseUrl}/start/formEngine/form/synchronizationTable/${tableId}`,
            method: 'get',

        }
    )
}
export const getAllStorage = () => {
    return request({
            url: `${baseUrl}/start/formEngine/form/getAllStorage`,
            method: 'get',
        }
    )
}
export const saveOrUpdate = (data, synchronization = false) => {
    console.log("synchronization", synchronization)
    console.log("保存数据", data)
    if (data.id) {
        return updateById(data, synchronization);
    }
    return add(data, synchronization)
}
const formApi = {
    list,
    pageHistory,
    add,
    getById,
    updateById,
    saveOrUpdate,
    deleteById,
    getByTableId,
    createMenu,
    getTableOption,
    saveTableOption,
    synchronizationTable,
    getAllStorage,
}
export default formApi
